<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Brochure Pagination
 *
 * @author Samuel Pulta
 */
class Brochure_Pagination extends Brochure {
    //put your code here
    
    //public $unique_id;
    public $id;
    public $page_num;	
    public $brochure_name;	
    public $brochure_description;	
    public $brochure_json;	
    public $brochure_content;	
    public $user_id;	
    public $status;	
    public $date_created;	
    public $date_modified;	
    public $is_active;	


    
    public function __construct($db, $id) {
        $this->init($db, $id);
    }
    
    public function init($db, $id){
        $this->db = $db;
        $this->tblname = TB_BROCHURE_PAGINATION;
        $this->id = $id;
        
            if($id){
                $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "row");
    
                $this->id   =   $result['id'];
                $this->page_num	   =   $result['page_num'];
                $this->brochure_name   =   $result['brochure_name'];	
                $this->brochure_description   =   $result['brochure_description'];	
                $this->brochure_json   =   $result['brochure_json'];	
                $this->brochure_content   =   $result['brochure_content'];	
                $this->user_id   =   $result['user_id'];	
                $this->status   =   $result['status'];	
                $this->date_created   =   $result['date_created'];	
                $this->date_modified   =   $result['date_modified'];	
                $this->is_active   =   $result['is_active'];	


            }
       
    }
    
    public function query_array(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "array");
        return  $result;
    }
    
    public function query_numrows(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname), "numrows");
        return $result;
    }
    
    public function save() {
        $insert_array = array(
            //"id"                        =>  $this->id,
            "page_num"                  =>  $this->page_num,	
            "brochure_name"             =>  $this->brochure_name,	
            "brochure_description"      =>  $this->brochure_description,	
            "brochure_json"             =>  $this->brochure_json,	
            "brochure_content"          =>  $this->brochure_content,	
            "user_id"                   =>  $this->user_id,	
            "status"                    =>  $this->status,	
            "date_created"              =>  $this->date_created,	
            "date_modified"             =>  $this->date_created,	
            "is_active"                 =>  $this->is_active

        );
    
        $insert_id = $this->db->insert($this->db->tbl_name($this->tblname), $insert_array);
    
        $this->id = $insert_id;
    }
    //
    public function update() {
        $update_array = array(
            //"id"                        =>  $this->id,
            "page_num"                  =>  $this->page_num,	
            "brochure_name"             =>  $this->brochure_name,	
            "brochure_description"      =>  $this->brochure_description,	
            "brochure_json"             =>  $this->brochure_json,	
            "brochure_content"          =>  $this->brochure_content,	
            "user_id"                   =>  $this->user_id,	
            "status"                    =>  $this->status,	
            "date_created"              =>  $this->date_created,	
            "date_modified"             =>  $this->date_created,	
            "is_active"                 =>  $this->is_active
        );
    
        $condition_array = array("id" => $this->id);
    
        $this->db->update($this->db->tbl_name($this->tblname), $update_array, $condition_array);
    }
}

?>
